<template>
  <div class="app-container overflow_yAuto">
    <div>
      <div slot="header" class="clearfix job-tab-header">
        <span class="span-title">登录日志监控管理</span>
      </div>
      <div>
        <div class=" select-container" style="margin-top:-15px">
          <el-row class="">
            <el-col class="">
              <el-form ref="form"  label-position='right' size="small" :inline="true" label-width="110px">
                <el-col :span="5" >
                  <el-form-item label="" prop="subsys_name" size='small'  style="margin:12px 0px;">
                      <el-input
                        size="small"
                        style="width: 200px;"
                        class="filter-item"
                        placeholder="输入登录名"
                        clearable
                        v-model="postList.condition.username.value"
                        prefix-icon="el-icon-search"
                        ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="5" >
                  <el-form-item label="" prop="en_subsys_name" size='small'  style="margin:12px 1px;">
                      <el-input
                        size="small"
                        style="width: 200px;"
                        class="filter-item"
                        placeholder="输入用户名"
                        clearable
                        v-model="postList.condition.name.value"
                        prefix-icon="el-icon-search"
                      ></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="10">
                  <div style="margin:12px 5px;">
                    <div style="display: inline-block;vertical-align: middle;width: 45%;" >
                      <el-date-picker
                        size="small"
                        style="width: 100%;"
                        v-model="postList.condition.beginlogintime.value"
                        format="yyyy-MM-dd HH:mm:ss"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        type="datetime"
                        placeholder="选择时间">
                      </el-date-picker>
                    </div>
                    <span style="display: inline-block;vertical-align: middle;padding: 0 6px;">至</span>
                    <div style="display: inline-block;vertical-align: middle;width: 45%;">
                      <el-date-picker
                        size="small"
                        style="width: 100%;"
                        v-model="postList.condition.endlogintime.value"
                        format="yyyy-MM-dd HH:mm:ss"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        type="datetime"
                        placeholder="选择时间">
                      </el-date-picker>
                    </div>
                  </div>
                </el-col>
                <el-col :span="4" style="text-align: left;">
                  <el-button size="small" style="height:30px;padding-top:0px;line-height:30px;margin:12px 0px;" type="success" icon="el-icon-edit" @click="fetchData('find')">查 询</el-button>
                  <el-button size="small" style="height:30px;padding-top:0px;line-height:30px;" type="danger" icon="el-icon-circle-close-outline" @click="handleReset">重 置</el-button>
                </el-col>
              </el-form>
            </el-col>
          </el-row>
        </div>
      </div>
    </div>
      <div>
        <el-table
          :key='tableKey'
          :data="list.records"
           v-loading="listLoading"
          element-loading-text="给我一点时间"
          size="small"
          stripe
          height="280px"
          style="width: 100%;border:#eeeeee"
          highlight-current-row>
          <el-table-column
            align="center"
            type="index"
            width="80"
            label="序号"
          >
            <template slot-scope="scope">
            <span>{{scope.$index + (serialNumber - 1) * postList.rowBounds.limit + 1}}</span>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="登录名"
            prop="username"
          >
          </el-table-column>

          <el-table-column
            align="center"
            label="用户名"
            prop="name"
          >
          </el-table-column>
          <el-table-column
            align="center"
            label="登录时间"
            prop="logintime"
          >
          </el-table-column>
          <el-table-column
            align="center"
            label="登出时间"
            prop="logouttime"
          >
          </el-table-column>
          <el-table-column
            align="center"
            label="动作"
            prop="action"
          >
          </el-table-column>
        </el-table>
        <div class="pagination-container">
          <el-pagination
            layout="total, sizes, prev, pager, next, jumper"
            :page-size = "postList.rowBounds.limit"
            :total="total"
            :page-sizes="[10,20,30, 50]"
            @current-change="current_change"
            @size-change="handleSizeChange"
          >
          </el-pagination>
        </div>
      </div>
    </div>
</template>

<script>
import '@/styles/newstyle.scss'
import {
  selectLoginLog
} from '@/api/systemManage/loginLogManagement'
export default {
  data() {
    return {
      dappendVisible: false,
      updateVisible: false,
      tableKey: 0,
      list: {},
      postList: {
        condition: {
          username: {
            property: 'username',
            value: '',
            type: 'LIKE'
          },
          name: {
            property: 'name',
            value: '',
            type: 'LIKE'
          },
         beginlogintime: {
           property: 'logintime',
           value: '',
           type: 'GE'
         },
         endlogintime: {
            property: 'logintime',
            value: '',
            type: 'LE'
          }
        },
        sort: [{
          direction: 'DESC',
          property: 'logintime'
        }],
        rowBounds: {
          offset: 0,
          limit: 10
        }
      },
      total:0,
      listLoading: false,
      serialNumber:1
    }
  },
  // 画面刚进入method
  created() {
    this.fetchData()
  },
  methods: {
    fetchData(flag) {
      this.listLoading = true
      if (flag == 'find') {
        this.postList.rowBounds.offset = 0
        this.serialNumber = 1
        this.total = 0
      }
      console.log('this.postList')
      console.log(this.postList)
      selectLoginLog(this.postList).then(res => {
        this.list = res.data.data
        this.total = res.data.data.count
        this.listLoading = false
      }).catch((err) => {
        console.log(err)
      })
    },
    current_change(currentPage) { // 通过分页获取数据
      this.serialNumber =currentPage
      const page = currentPage - 1
      this.postList.rowBounds.offset = page * this.postList.rowBounds.limit
      this.fetchData()
    },
    // 翻页器使用
    handleSizeChange(val) {
      this.postList.rowBounds.limit = val
      this.postList.rowBounds.offset = this.postList.rowBounds.limit * (this.serialNumber - 1)
      this.list = null
      this.fetchData()
    },
    handleReset() {
      this.postList.condition.username.value = ''
      this.postList.condition.name.value = ''
      this.postList.condition.beginlogintime.value = ''
      this.postList.condition.endlogintime.value = ''
      this.postList.rowBounds.limit = 10
      this.postList.rowBounds.offset = 0
      this.serialNumber =1
      this.list.records = null
      this.total = 0
      this.fetchData()
    }
  }
}
</script>

<style scoped>
  .container{
    color: #3b96f3;
    background: #fff;
    padding: 20px;
    height: 100%;
    overflow-y: auto;
  }
  .select-container{
    padding: 10px 10px;
    margin-bottom: 10px;
    border-radius: 4px;
    border: 1px solid #eeeeee;
  }
  .list-container{
    margin-top:30px;
    padding:0 10px 10px 10px;
    border:1px solid#eeeeee;
    border-radius: 4px;
  }
  .data-contant{
    background-color: rgba(0,0,0,.035);
    padding: 30px 10px 20px;
  }
  .data-detail{
    font-size: 14px;
    padding:20px 0;
    text-align: center;
  }
  .data-title{
    font-size: 14px;
    padding:10px 0;
    text-align: center;
  }
  .data-title div{
    font-size: 14px;
    padding:5px 0;
  }
  .filter{
    padding: 10px 5px;
    border-bottom: 2px solid#eeeeee;
  }
  .list-container{
  }
  .bold{
    font-weight: bold;
  }
</style>
